﻿<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace='Indicator' xmlns='http://ibatis.apache.org/mapping' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
  <alias>
    <typeAlias alias='Indicator' assembly='Janus.Mes.POCO.dll' type='Janus.Mes.POCO.Indicator' />
  </alias>
  <resultMaps>
    <resultMap id='IndicatorResult' class='Indicator'>
      <result property='Id' column='Id' />
      <result property='IndicatorName' column='IndicatorName' />
      <result property='IndicatorFiledName' column='IndicatorFiledName' />
      <result property='IndicatorValue' column='IndicatorValue' />
      <result property='CreateDt' column='CreateDt' />
    </resultMap>
    <resultMap id='IndicatorResult' class='Indicator'>
      <result property='Id' column='Id' />
      <result property='IndicatorName' column='IndicatorName' />
      <result property='IndicatorFiledName' column='IndicatorFiledName' />
      <result property='IndicatorValue' column='IndicatorValue' />
      <result property='CreateDt' column='CreateDt' />
    </resultMap>
    <resultMap id="account-result-constructor" class="Account" >
      <constructor>
        <argument argumentName="id" column="Account_ID"/>
        <argument argumentName="firstName" column="Account_FirstName"/>
        <argument argumentName="lastName" column="Account_LastName"/>
      </constructor>
      <result property="EmailAddress" column="Account_Email" nullValue="no_email@provided.com"/>
      <result property="BannerOption" column="Account_Banner_Option" dbType="Varchar" type="bool"/>
      <result property="CartOption"	column="Account_Cart_Option" typeHandler="HundredsBool"/>
    </resultMap>
    <resultMap id="get-product-result" class="product">
      <result property="id" column="PRD_ID"/>
      <result property="description" column="PRD_DESCRIPTION"/>
      <result property="subCode" column="PRD_SUB_CODE" nullValue="-9999"/>
    </resultMap>
    <resultMaps>
      <resultMap id="boc-result"  class="BudgetObjectCode">
        <result property="Code" column="BOC_CODE" dbType="Varchar2"/>
        <result property="Description" column="BOC_DESC" dbType="Varchar2"/>
        <result property="GuidProperty" column="BOC_GUID" typeHandler="GuidVarchar"/>
      </resultMap>
    </resultMaps>
    <resultMaps>
      <resultMap id="boc-result"  class="BudgetObjectCode">
        <result property="Code" column="BOC_CODE" dbType="Varchar2"/>
        <result property="Description" column="BOC_DESC" dbType="Varchar2"/>
        <result property="GuidProperty" column="BOC_GUID" dbType="Varchar2" type="guid"/>
      </resultMap>
      <resultMap id="document" class="Document">
        <result property="Id" column="Document_ID"/>
        <result property="Title" column="Document_Title"/>
        <discriminator column="Document_Type" type="string"/>
        <subMap value="Book" resultMapping="book"/>
        <subMap value="Newspaper" resultMapping="newspaper"/>
      </resultMap>

      <resultMap id="book" class="Book" extends="document">
        <result property="PageNumber" column="Document_PageNumber"/>
      </resultMap>

      <resultMap id="newspaper" class="Newspaper"  extends="document">
        <result property="City" column="Document_City"/>
      </resultMap>
      <resultMap id="select-category-result" class="Category">
        <result property="Id" column="CAT_ID"/>
        <result property="Description" column="CAT_DESCRIPTION"/>
        <result property="ProductList" column="CAT_ID" select="selectProductsByCatId"/>
      </resultMap>
      <resultMap id="Category-result" class="Category" groupBy="Id">
        <result property="Id" column="CAT_ID"/>
        <result property="Description" column="CAT_DESCRIPTION"/>
        <result property="ProductList" resultMapping="ProductCategory.Product-result"/>
      </resultMap>
    </resultMaps>
  </resultMaps>
  <cacheModel id="product-cache" implementation="LRU">
    <flushInterval hours="24"/>
    <flushOnExecute statement="insertProduct"/>
    <flushOnExecute statement="updateProduct"/>
    <flushOnExecute statement="deleteProduct"/>
    <property name="size" value="1000" />
  </cacheModel>
  <cacheModel id="product-cache2" implementation="LRU">
    <flushInterval hours="24"/>
    <flushOnExecute statement="insertProduct"/>
    <flushOnExecute statement="updateProduct"/>
    <flushOnExecute statement="deleteProduct"/>
    <property name="size" value="1000" />
  </cacheModel>
  <parameterMaps>
    <parameterMap id="PageMap" class="PageCriteria">
      <parameter property="TableName" />
      <parameter property="PrimaryKey"/>
      <parameter property="Fields" />
      <parameter property="Condition" />
      <parameter property="CurrentPage" />
      <parameter property="PageSize" />
      <parameter property="Sort" />
      <parameter property="RecordCount" direction="Output" column="RecordCount"/>
    </parameterMap>
    <parameterMap id="PageMap" class="PageCriteria">
      <parameter property="TableName" />
      <parameter property="PrimaryKey"/>
      <parameter property="Fields" />
      <parameter property="Condition" />
      <parameter property="CurrentPage" />
      <parameter property="PageSize" />
      <parameter property="Sort" />
      <parameter property="RecordCount" direction="Output" column="RecordCount"/>
    </parameterMap>
    <parameterMap id="insert-params">
      <parameter property="Id"           dbType="Int32"/>
      <parameter property="FirstName"    dbType="VarChar2" size="32"/>
      <parameter property="LastName"     dbType="VarChar2" size="32"/>
      <parameter property="EmailAddress" dbType="VarChar2" size="128"/>
    </parameterMap>
  </parameterMaps>
  
  <statements>
    <sql id="UpdaterConditions">
      <isPropertyAvailable prepend="" property="IndicatorName">
        <isNotEmpty prepend="" property="IndicatorName">
          [IndicatorName]=#IndicatorName#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorFiledName">
        <isNotEmpty prepend="," property="IndicatorFiledName">
          [IndicatorFiledName]=#IndicatorFiledName#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorValue">
        <isNotEmpty prepend="" property="IndicatorValue" >
          <isNotEqual prepend="," property="IndicatorValue" compareValue="0">
            [IndicatorValue]=#IndicatorValue#
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="CreateDt">
        <isNotEmpty prepend="," property="CreateDt">
          [CreateDt]=#CreateDt#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="Bit">
        <isNotEmpty prepend="," property="Bit">
          [IntNull]=#IntNull#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IntNotNull">
        <isNotEmpty prepend="" property="IntNotNull">
          <isNotEqual prepend="," property="IntNotNull" compareValue="0">
            [IntNotNull]=#IntNotNull#
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="Bit">
        <isNotEmpty prepend="," property="Bit">
          [Bit]=#Bit#
        </isNotEmpty>
      </isPropertyAvailable>
    </sql>
    <sql id="WhereConditions">
      <isPropertyAvailable prepend="" property="IndicatorName">
        <isNotEmpty prepend="" property="IndicatorName">
          [IndicatorName]=#IndicatorName# AND
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorFiledName">
        <isNotEmpty prepend="" property="IndicatorFiledName">
          [IndicatorFiledName]=#IndicatorFiledName# AND
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorValue">
        <isNotEmpty prepend="" property="IndicatorValue" >
          <isNotEqual prepend="" property="IndicatorValue" compareValue="0">
            [IndicatorValue]=#IndicatorValue# AND
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="CreateDt">
        <isNotEmpty prepend="" property="CreateDt">
          [CreateDt]=#CreateDt# AND
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="Bit">
        <isNotEmpty prepend="" property="Bit">
          [Bit]=#Bit# AND
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IntNotNull">
        <isNotEmpty prepend="" property="IntNotNull">
          <isNotEqual prepend="" property="IntNotNull" compareValue="0">
            [IntNotNull]=#IntNotNull# AND
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="Bit">
        <isNotEmpty prepend="" property="Bit">
          [Bit]=#Bit# AND
        </isNotEmpty>
      </isPropertyAvailable>
    </sql>
    <sql id="InsertPublic">
      INSERT INTO Indicator(
      <isPropertyAvailable prepend="" property="IndicatorName">
        <isNotEmpty prepend="" property="IndicatorName">
          [IndicatorName]
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorFiledName">
        <isNotEmpty prepend="," property="IndicatorFiledName">
          [IndicatorFiledName]
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorValue">
        <isNotEmpty prepend="" property="IndicatorValue" >
          <isNotEqual prepend="," property="IndicatorValue" compareValue="0">
            [IndicatorValue]
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="CreateDt">
        <isNotEmpty prepend="," property="CreateDt">
          [CreateDt]
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IntNull">
        <isNotEmpty prepend="," property="IntNull">
          [IntNull],
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IntNotNull">
        <isNotEmpty prepend="" property="IntNotNull">
          <isNotEqual prepend="," property="IntNotNull" compareValue="0">
            [IntNotNull]
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="Bit">
        <isNotEmpty prepend="," property="Bit">
          [Bit]
        </isNotEmpty>
      </isPropertyAvailable>
      )
      VALUES
      (
      <isPropertyAvailable prepend="" property="IndicatorName">
        <isNotEmpty prepend="" property="IndicatorName">
          #IndicatorName#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorFiledName">
        <isNotEmpty prepend="," property="IndicatorFiledName">
          #IndicatorFiledName#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IndicatorValue">
        <isNotEmpty prepend="" property="IndicatorValue">
          <isNotEqual prepend="," property="IndicatorValue" compareValue="0">
            #IndicatorValue#
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="CreateDt">
        <isNotEmpty prepend="," property="CreateDt">
          #CreateDt#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IntNull">
        <isNotEmpty prepend="," property="IntNull">
          #IntNull#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IntNotNull">
        <isNotEmpty prepend="" property="IntNotNull">
          <isNotEqual prepend="," property="IntNotNull" compareValue="0">
            #IntNotNull#,
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="Bit">
        <isNotEmpty prepend="," property="Bit">
          #Bit#
        </isNotEmpty>
      </isPropertyAvailable>
      )
    </sql>
    <!-- Insert statement:新增Mapper-->
    <insert id='Insert' parameterClass='Indicator' parameterMap=''>
      <include refid="InsertPublic"/>
    </insert>
    <insert id='Insert' parameterClass='Indicator' parameterMap=''>
      <isPropertyAvailable prepend="" property="CreateDt">
        <isNotEmpty prepend="," property="CreateDt">
          [CreateDt]=#CreateDt#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="Bit">
        <isNotEmpty prepend="," property="Bit">
          [IntNull]=#IntNull#
        </isNotEmpty>
      </isPropertyAvailable>
      <isPropertyAvailable prepend="" property="IntNotNull">
        <isNotEmpty prepend="" property="IntNotNull">
          <isNotEqual prepend="," property="IntNotNull" compareValue="0">
            [IntNotNull]=#IntNotNull#
          </isNotEqual>
        </isNotEmpty>
      </isPropertyAvailable>
    </insert>
    <!--Update statement:修改Mapper-->
    <update id='Update' parameterClass='Indicator' extends=''>
      UPDATE Indicator SET
      <include refid="UpdaterConditions"/>
      WHERE ID=#Id#
    </update>
    <update id='UpdateSetion' parameterClass='hashtable'>
      UPDATE Indicator SET
      <include refid="UpdaterConditions"/>
      WHERE $conditions$
    </update>
    <update id='Save' parameterClass='Indicator'>
      IF NOT EXISTS(SELECT 1 FROM [Indicator] WHERE Id=#Id#)
      BEGIN
      <include refid="InsertPublic"/>
      END
      ELSE
      BEGIN
      UPDATE Indicator SET
      <include refid="UpdaterConditions"/>
      WHERE ID=#Id#
      END
    </update>
    <delete id='Delete' parameterClass='string' extends=''>
      DELETE FROM [Indicator] WHERE ID=#value#
    </delete>
    <delete id='DeleteWhere' parameterClass='string'>
      DELETE FROM [Indicator] WHERE $value$
    </delete>

    <!-- select by key statement:-->
    <select id='FindOne' parameterClass='list' resultClass='Indicator' listClass='' parameterMap=''  resultMap=''  cacheModel='' extends=''>
      SELECT * FROM Indicator WHERE
      <iterate open="(" close=")" conjunction="AND">
        <![CDATA[  
           [ID]= #[]# 
        ]]>
      </iterate>
    </select>
    <select id='FindAllCondition' parameterClass='string' resultClass='Indicator'>
      SELECT * FROM [Indicator] WHERE $value$
    </select>
    <select id='FindScalar' parameterClass='hashtable' resultClass='Indicator'>
      SELECT * FROM [Indicator] WHERE $conditions$
    </select>
    
    <select id='FindAllCount' parameterClass='string' resultClass='int'>
      SELECT COUNT(1) FROM [Indicator] WHERE $value$
    </select>
    <select id='FindByPage' parameterClass='string' resultClass='Indicator'>
      SELECT * FROM [Indicator] WHERE $value$
    </select>
     <procedure id="ProcGetPageData" parameterMap="PageMap" resultClass="Hashtable" resultMap="" cacheModel="" >
      [dbo].[ProcGetPageData]
    </procedure>  

  </statements>

</sqlMap>
